#include "widget.h"
#include "ui_widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->tabWidget->setTabShape(QTabWidget::Triangular);
}

Widget::~Widget()
{
    if(loader.isLoaded())
    {
        loader.unload();
    }
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QDir dir(qApp->applicationDirPath());   //获取程序路径
    loader.setFileName(dir.filePath("PluginDemo.dll")); //设置加载器路径并加载对应插件
    if(!loader.load()){
        qDebug() << loader.errorString();   //加载失败时提示错误
        return;
    }
    PluginDemointerface *pi = qobject_cast<PluginDemointerface*>(loader.instance());    //强制类型转换，引出对象
    if(pi){
        QWidget *wq = pi->widgetshow();
        if(wq){
            ui->tabWidget->addTab(wq,"这是我自定义的插件");  //插件加载到对应页面
        }
    }
}

